const { check, validationResult } = require('express-validator')

var checks = {}


checks.userLogin = () => {
    return [
        check("user_account")
            .isLength({ min: 5, max: 50 })
            .withMessage("字符串长度不合法"),
            // .isBase64()
            // .withMessage("参数不合法"),
        check("user_password")
            .isLength({ min: 6, max: 30 })
            .withMessage("字符串长度不合法")
    ]
}

checks.blogUpload = () => {
    return [
        check("blog_title")
            .isLength({ min: 1, max: 60 })
            .withMessage("字符串长度不合法"),
        check("blog_abstract")
            .isLength({ min: 0, max: 60 })
            .withMessage("字符串长度不合法"),
        check("blog_category_id")
            .isLength({ min: 1, max: 60 })
            .withMessage("分类错误"),
        check("blog_content")
            .isLength({ min: 4, max: 1024 * 1024 * 1024 * 1 })
            .withMessage("字符串长度不合法")
    ]
}

checks.categoryUpload = (data) => {
    return [
        check("blog_category_name")
            .isLength({ min: 1, max: 50 })
            .withMessage("字符串长度不合法")
    ]
}

checks.uploadFiles = () => {
    return [
        check("file_hash")
            .isLength({ min: 31, max: 33 })
            .withMessage("字符串长度不合法")
            .isMD5()
            .withMessage("类型不合法"),
        check("chunk_num")
            .isLength({ min: 1, max: 5 })
            .withMessage("字符串长度不合法")
    ]
}


checks.userRegister = () => {
    return [
        check("user_account")
            .isLength({ min: 5, max: 50 })
            .withMessage("字符串长度不合法"),
        check("user_password")
            .isLength({ min: 6, max: 30 })
            .withMessage("字符串长度不合法"),
        check("user_email")
            .isEmail()
            .withMessage("必须是正确的电子邮件"),
    ]
}


checks.userFileList = () => {
    return [
        check("folder_path")
            .isLength({ min: 0, max: 50 })
            .withMessage("字符串长度不合法")
    ]
}

module.exports = { checks }